<?php
/*
 * 1626cms 個人會員函數
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
 */
if(!defined('IN_QISHI'))
{
	die('Access Denied!');
}
//添加期望崗位性質
function add_intention_nature($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!is_numeric(str_replace(",","",implode(",",$arr)))) return false;
	if (!$db->query("Delete from ".table('resume_intention_nature')." WHERE uid='".$uid."' ")) return false;
	foreach ($arr as $value){
		if (!$db->query("INSERT INTO ".table('resume_intention_nature')." (id,uid,jid) VALUES (NULL,'$uid','$value')")) return false;
	}
	return true;
}
//添加期望工作職位
function add_intention_jobs($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!is_numeric(str_replace(",","",implode(",",$arr)))) return false;
	if (!$db->query("Delete from ".table('resume_intention_jobs')." WHERE uid='".$uid."' ")) return false;
	foreach ($arr as $value){
		$category_one=get_jobs_category_one($value);
		$category=$category_one['ParentID'];
		if (!$db->query("INSERT INTO ".table('resume_intention_jobs')." (id,uid,category,subclass) VALUES (NULL,'$uid','$category','$value')")) return false;
	}
	return true;
}
//添加期望工作地區
function add_intention_area($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!is_numeric(str_replace(",","",implode(",",$arr)))) return false;
	if (!$db->query("Delete from ".table('resume_intention_area')." WHERE uid='".$uid."' ")) return false;
	foreach ($arr as $value){
		if (!$db->query("INSERT INTO ".table('resume_intention_area')." (id,uid,jid) VALUES (NULL,'$uid','$value')")) return false;
	}
	return true;
}
//添加期望工作期望行業
function add_intention_trade($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!is_numeric(str_replace(",","",implode(",",$arr)))) return false;
	if (!$db->query("Delete from ".table('resume_intention_trade')." WHERE uid='".$uid."' ")) return false;
	foreach ($arr as $value){
		if (!$db->query("INSERT INTO ".table('resume_intention_trade')." (id,uid,jid) VALUES (NULL,'$uid','$value')")) return false;
	}
	return true;
}
//添加教育背景
function add_education($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("INSERT INTO ".table('resume_education')." (id,uid,school,speciality,education,ways,getday) VALUES (NULL,'$uid','".$arr['school']."','".$arr['speciality']."','".$arr['education']."','".$arr['ways']."','".$arr['getday']."')")) return false;
	return true;
}
//修改教育背景
function edit_education($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("update  ".table('resume_education')."  SET start='".$arr['start']."', endtime='".$arr['endtime']."', school='".$arr['school']."', speciality='".$arr['speciality']."',education='".$arr['education']."',ways='".$arr['ways']."',getday='".$arr['getday']."'  WHERE uid='".$uid."' AND id='".$arr['id']."'")) return false;
	return true;
}
//添加工作經歷
function add_work($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("INSERT INTO ".table('resume_work')." (id,uid,start,endtime,companyname,companyprofile,jobs,achievements,nature,salary,salary2) VALUES (NULL,'$uid','".$arr['start']."','".$arr['endtime']."','".$arr['companyname']."','".$arr['companyprofile']."','".$arr['jobs']."','".$arr['achievements']."','".$arr['nature']."','".$arr['salary']."','".$arr['salary2']."')")) return false;
	return true;
}
//修改工作經歷
function edit_work($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("update  ".table('resume_work')."  SET start='".$arr['start']."', endtime='".$arr['endtime']."', companyname='".$arr['companyname']."', companyprofile='".$arr['companyprofile']."',jobs='".$arr['jobs']."',achievements='".$arr['achievements']."' ,nature='".$arr['nature']."' ,salary='".$arr['salary']."' ,salary2='".$arr['salary2']."'  WHERE uid='".$uid."' AND id='".$arr['id']."'")) return false;
	return true;
}
//添加工作經歷
function add_training($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("INSERT INTO ".table('resume_training')." (id,uid,start,endtime,agency,course,education,description) VALUES (NULL,'$uid','".$arr['start']."','".$arr['endtime']."','".$arr['agency']."','".$arr['course']."','".$arr['education']."','".$arr['description']."')")) return false;
	return true;
}
//修改工作經歷
function edit_training($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("update  ".table('resume_training')."  SET start='".$arr['start']."', endtime='".$arr['endtime']."', agency='".$arr['agency']."', course='".$arr['course']."', education='".$arr['education']."',description='".$arr['description']."'  WHERE uid='".$uid."' AND id='".$arr['id']."'")) return false;
	return true;
}
//修改簡歷照片
function edit_photo($uid,$arr)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (!is_array($arr))return false;
	if (!$db->query("Delete from ".table('resume_photo')." WHERE uid='".$uid."' ")) return false;
	if (!$db->query("INSERT INTO ".table('resume_photo')." (id,uid,photo,audit) VALUES (NULL,'$uid','".$arr['photo']."','".$arr['audit']."')")) return false;
	return true;
}
//修改簡歷照片顯示設置
function edit_photo_display($uid,$display)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	if (intval($display)!=$display) return false;
	if (!$db->query("update  ".table('resume_photo')."  SET display='".$display."' WHERE uid='".$uid."'")) return false;
	check_resume($uid);
	return true;
}
//檢查簡歷的完成程度
function check_resume($uid)
{
	global $db,$timestamp;
	if (intval($uid)!=$uid) return false;
	$resume_basic=get_resume_basic($uid);//簡歷基本資料
//	$resume_intention=get_resume_intention($uid);//求職意向
//	$resume_specialty=get_resume_specialty($uid);//技能特長
	$resume_photo=get_resume_photo($uid);//形象照片
//	if ($resume_basic && $resume_intention && $resume_specialty )
	if ($resume_basic )
	{
		$setsqlarr['complete']=1;
	}
	else
	{
		$setsqlarr['complete']=2;
	}
//	$setsqlarr['recentjobs']=$resume_intention['recentjobs'];
//	$setsqlarr['wage']=$resume_intention['wage'];
//	$setsqlarr['wage']=$resume_intention['wage'];
//	$setsqlarr['specialty']=$resume_specialty['specialty'];
//	$setsqlarr['refreshtime']=$timestamp;
	$resume_photo?$setsqlarr['photoresume']="2":$setsqlarr['photoresume']="1";
	$setsqlarr['photo']=$resume_photo['photo'];
	$setsqlarr['photo_audit']=$resume_photo['audit'];
	$setsqlarr['photo_display']=$resume_photo['display'];
//	$setsqlarr['key']=$resume_basic['fullname'].$resume_specialty['specialty'].$resume_intention['recentjobs'];
	$setsqlarr['key']=$resume_basic['fullname'];
	$wheresql=" uid='".$uid."' ";
	updatetable(table('resume'),$setsqlarr,$wheresql);
}
//獲取企業的面試邀請
function get_invitation_interview($offset,$perpage,$get_sql= ''){
	global $db;
	$row_arr = array();
	if(isset($offset)&&!empty($perpage))
	{
		$limit=" LIMIT ".$offset.','.$perpage;
	}
	$result = $db->query("SELECT * FROM ".table('company_invitation_interview')." ".$get_sql." ORDER BY personal_look DESC ".$limit);
	while($row = $db->fetch_array($result))
	{
		$row_arr[] = $row;
	}
	return $row_arr;
}
//獲取企業的詳細面試邀請（單條）,并修改為已經查看
function get_invitation_interview_one($id){
	global $db;
	if (intval($id)!=$id) return false;
	$sql = "select * from ".table('company_invitation_interview')." where did=".$id;
	$lsit=$db->getone($sql);
	$lsit['company_url']=url_rewrite('company',array('id0'=>$lsit['company_id']));
	$setsqlarr['personal_look']='2';
	$setsqlarr['did']=$id;
	$wheresql=" did='".$id."' ";
	updatetable(table('company_invitation_interview'),$setsqlarr,$wheresql);
	unset($setsqlarr);
	return $lsit;
}
//刪除 -邀請記錄
function del_invitation_interview($del_id,$uid)
{
	global $db;
	$uidsql=" AND resume_uid='".$uid."'";
	if (!is_array($del_id)) return false;
	$sqlin=implode(",",$del_id);
	if (!is_numeric(str_replace(",","",$sqlin))) return false;
	if (!$db->query("Delete from ".table('company_invitation_interview')." WHERE did IN (".$sqlin.") ".$uidsql."")) return false;
	return true;
}
//添加的職位收藏
function add_jobs_library($arr,$uid)
{
	global $db,$timestamp;
	if (intval($uid)!=$uid) return false;
	if (is_array($arr))
	{
		$setsqlarr['personal_uid']=$uid;
		$setsqlarr['jobs_id']=$arr['jobs_id'];
		$setsqlarr['jobs_name']=$arr['jobs_name'];
		$setsqlarr['company_id']=$arr['company_id'];
		$setsqlarr['company_name']=$arr['company_name'];
		$setsqlarr['addtime']=$timestamp;
		if ($arr['jobs_id'])
		{
			$total_sql="SELECT COUNT(*) AS num FROM ".table('personal_jobs_library')." WHERE jobs_id=".$arr['jobs_id']." AND personal_uid=".$uid."";
			if (get_total($total_sql)) return false;
		}
		inserttable(table('personal_jobs_library'),$setsqlarr);
		return true;
	}
}
//獲取職位收藏夾
function get_jobs_library($offset,$perpage,$get_sql= '')
{
	global $db;
	$row_arr = array();
	if(isset($offset)&&!empty($perpage))
	{
		$limit=" LIMIT ".$offset.','.$perpage;
	}
	$result = $db->query("SELECT * FROM ".table('personal_jobs_library')." ".$get_sql." ORDER BY did DESC ".$limit);
	while($row = $db->fetch_array($result))
	{
		$row['company_url']=url_rewrite('company',array('id0'=>$row['company_id']));
		$row['jobs_url']=url_rewrite('jobs-show',array('id0'=>$row['jobs_id']));
		$row_arr[] = $row;
	}
	return $row_arr;
}
//檢測職位是否申請過
function check_jobs_apply($jobs_id,$p_uid)
{
	global $db;
	if (intval($jobs_id)!=$jobs_id) return false;
	$sql = "select * from ".table('personal_jobs_apply')." WHERE personal_uid = '$p_uid' AND jobs_id='$jobs_id'";
	$info=$db->getone($sql);
	if ($info) return true;
	else return false;
}
//獲取申請職位列表
function get_jobs_apply($offset,$perpage,$get_sql= '')
{
	global $db;
	$row_arr = array();
	if(isset($offset)&&!empty($perpage))
	{
		$limit=" LIMIT ".$offset.','.$perpage;
	}
	$result = $db->query("SELECT * FROM ".table('personal_jobs_apply')." ".$get_sql." ORDER BY did DESC ".$limit);
	while($row = $db->fetch_array($result))
	{
		$row['company_url']=url_rewrite('company',array('id0'=>$row['company_id']));
		$row['jobs_url']=url_rewrite('jobs-show',array('id0'=>$row['jobs_id']));
		$row_arr[] = $row;
	}
	return $row_arr;
}
//刪除 -申請職位記錄
function del_jobs_apply($del_id,$uid)
{
	global $db;
	$uidsql=" AND personal_uid='".$uid."'";
	if (!is_array($del_id)) return false;
	$sqlin=implode(",",$del_id);
	if (!is_numeric(str_replace(",","",$sqlin))) return false;
	if (!$db->query("Delete from ".table('personal_jobs_apply')." WHERE did IN (".$sqlin.") ".$uidsql."")) return false;
	return true;
}
//面試邀請總數
function count_invitation_interview($uid)
{
	$wheresql=" WHERE resume_uid='".$uid."' ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('company_invitation_interview').$wheresql;
	return get_total($total_sql);
}
//申請職位總數
function count_personal_jobs_apply($uid)
{
	$wheresql=" WHERE personal_uid='".$uid."' ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('personal_jobs_apply').$wheresql;
	return get_total($total_sql);
}
//職位收藏夾總數
function count_jobs_library($uid)
{
	$wheresql=" WHERE personal_uid='".$uid."' ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('personal_jobs_library').$wheresql;
	return get_total($total_sql);
}
//用戶反饋列表
function get_feedback($uid)
{
	global $db;
	$sql = "select * from ".table('feedback')." where uid='".$uid."' ORDER BY id desc";
	$list=$db->getall($sql);
	return $list;
}
//刪除用戶反饋
function del_feedback($del_id,$uid)
{
	global $db;
	if (intval($del_id)!=$del_id) return false;
	if (!$db->query("Delete from ".table('feedback')." WHERE id='".intval($del_id)."' AND uid='".intval($uid)."'  ")) return false;
	return true;
}
?>
